In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Molecular biologists have been studying genomes (i.e. sequences of genes) of particular organisms, trying to infer some conclusions about evolution of species and operation of cells and tissues. In their research they compare the structure and functions of respective genes and they identify genes very similar to each other (called homologous genes).
Recently, while examining viruses attacking bacteria (called bacteriophages or simply phages), they observed a very intriguing phenomenon. If sequences of genes of some phages are arranged one below another and homologous genes are coloured with the same colour, then a peculiar mosaic is obtained:
To describe the phenomenon that they discovered, scientists invented a measure that they called the coefficient of mosaicism. This coefficient can be computed for a phage only in juxtaposition with some other phages - it is then equal to the total number of points computed in the following way. For every two genes from the -th phage and for every two different phages such that:
In the situation illustrated in the above figure, phage number has the coefficient of mosaicism equal to . That is because the blue gene has a homologous gene in phage and does not have any in phage ; on the other hand, the orange gene has a homologous gene in phage and does not have any in phage . A similar situation holds for genes: brown and orange. Phage number has the coefficient of mosaicism equal to - it receives points for pairs of genes: red-blue, red-brown, 2 times yellow-blue and 2 times yellow-brown.
Manual computation of the coefficients is quite difficult, so the biologists decided to ask you to write a program that would compute the coefficients of mosaicism of all given phages.
Write a program that:
The first line of input contains one integer () denoting the number of phages under consideration.
The -th of the following lines contains a description of the sequence of genes of the -th phage. Each such description starts with a single integer () denoting the number of genes in the -th phage's sequence, which is followed by integers () describing its successive genes. All these numbers are separated with single spaces.
Two genes are considered homologous if and only if they are represented by equal numbers in the description from the input. The scientists proved that no two genes of a phage can be homologous1, so no number can appear an a description of a single phage twice.
The output should consist of lines. -th of them should contain a single integer equal to the coefficient of mosaicism of the -th phage.
For the input data:
4 4 1 5 2 4 3 3 6 4 3 5 2 6 3 4 3 1
the correct result is:
6 3 2 1
The figure from the task description illustrates the example test case.
Task author: Aleksander Mielczarek.